home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Browsers, Managers & Extensions
/
Firefox Backup Extension 6.0.3
/
chrome
/
febe.jar
/
content
/
febeCommon.js
< prev
next >
Wrap
Text File
|
2008-09-07
|
35KB
|
955 lines
// author: Chuck Baker
// contact: febe@customsoftwareconsult.com
// Version 6.0
// Common (global) variables
var Cc = Components.classes;
var Ci = Components.interfaces;
// These should be constants, but CLEO opens this file and re-declares them
var FEBE_GUID = "{4BBDD651-70CF-4821-84F8-2B918CF89CA3}" // GUID of this extension
var FEBEDATAFILE = "febeUserDefinedBuData.json";
// Get pointer to preferences
try{
var febePrefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("");
}catch(e){
var msg = febeMsg[169];
febeFatal(e,msg);}
function febeGetUnicharPref(prefName) {
return febePrefs.getComplexValue(prefName, Ci.nsISupportsString).data;
}
function febeSetUnicharPref(prefName, prefValue) {
var supportsString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
supportsString.data = prefValue;
febePrefs.setComplexValue(prefName, Ci.nsISupportsString, supportsString);
}
// Set global variables
var febeBUtype = new String(); // "selective" or "profile"
var febeExBuDir = new String(); // Directory where the results are stored
var febeBUdate = new Date(); // Date of backup to restore
var febePathName = new String(); // Holds full path name of various files
var febeExtensionsList = {}; // Array holding extension names
var febeThemesList = {}; // Array holding theme names
var febeErrorList = []; // Array holding failed items (errors)
var febeWarningList = []; // Array holding failed items (warnings)
var febeETinstall = []; // Array of ext/theme objects to install
var febeMsg = []; // Array holding localized strings
var febeTmpDir = new String(); // nsIFile pointer to temp directory
var febeDestDir = new String(); // nsIFile pointer used in febeDirCopy()
var febeSubRootDir = new String(); // Used in febeDirCopy()
var febeBuSeq = new String(); // FEBE Batch Sequence number
var FEBEdir = new String(); // Pointer to FEBE extension directory
var febeWin = new Object; // Window object for FEBE windows
var febeProfDir = new String(); // Pointer to profile directory
var febeProfName = new String(); // Profile name
var febeVersion = new String(); // Version of this extension (FEBE)
var febePrName = new String(); // Leafname of file picker file
var febePfName = new String() // Same as febePrName
var febePfParent = new String() // Parent directory of filel picker file
var febeBuDesDir = new String(); // Pointer to backup destination directory
var febeExtExt = new String(); // ".xpi" (extension) or ".jar" (theme)
var febeInitialized; // Initalize function run yet?
var febeUseTimestampedDir = new Boolean(false);// Create timestamped subdirectories?
var febeMaxDirs = new Number; // Maximum number of timestamped directories
var febeClearDestDir = new Boolean(false); // Clear destination directory?
var febeProfList = []; // Array of febeProfileObj objects
var febePlatform = new Number; // 1=Windows, 2=*nix, 3=Mac
//var febePathDelimiter = new String(); // Backslash for Windows, slash for Linux
var febeDisabledCount = new Number; // Count of disabled extensions
var includeFEBE = new String(); // Include a copy of FEBE with backup?
var febeUDBuDone = []; // Array of completed User-defined backups
var febeClipboard = []; // Holds alert messages for the clipboard
var febeIgnoreError; // Error to ignore
var febeReminded; // If true, dont show backup reminder
var febeWelcomePage = new String(); // URL of welcome page
var febex; // Misc flag
var febeWait; // Number of milliseconds until next scheduled backup
var febeDataFile; // Pointer to FEBEDATAFILE
var febeUploadAborted; // Monitors box.net upload
var febeAlertFinalHeight; // Used in alert messages
// Preferences
var buExtensions = new Boolean(false); // Backup extensions?
var buThemes = new Boolean(false); // Backup themes?
var buBookmarks = new Boolean(false); // Backup bookmarks.html?
var buPreferences = new Boolean(false); // Backup prefs.js?
var buCookies = new Boolean(false); // Backup cookies.txt?
var buUserChrome = new Boolean(false); // Backup userChrome.css?
var buUserPwd = new Boolean(false); // Backup key3.db and signons.txt?
var buSearchPlugins = new Boolean(false); // Backup searchplungins directory?
var buBrowserHistory = new Boolean(false); // Backup history.dat?
var buFormFillHistory = new Boolean(false); // Backup formhistory.dat?
var buPermissions = new Boolean(false); // Backup hostperm.1?
var buUDBu = new Boolean(false); // Backup User-defined backups?
var buProfile = new Boolean(false); // Backup entire profile?
var ignoreDisabled = new Boolean(false); // Ignore disabled extension?
var febeHideIcons = new Boolean(false); // Hide statusbar icons?
var febeVerifyBackups = new Boolean(false); // Verify backups?
var febeHideHelp = new Boolean(false); // Hide help icons?
var febeDispProgress = new Boolean(false); // Display progress window?
var febeDispResults = new Boolean(false); // Display results page?
var febeSaveResults = new Boolean(false); // Save results page?
var febePlaySounds = new Boolean(false); // Play sounds?
// Backup flags
var exBackedUp = new Boolean(false); // Did extensions backup ok?
var thBackedUp = new Boolean(false); // Did themes backup ok?
var bmBackedUp = new Boolean(false); // Did bookmarks backup ok?
var prBackedUp = new Boolean(false); // Did the preferences backup ok?
var ckBackedUp = new Boolean(false); // Did cookies backup ok?
var chBackedUp = new Boolean(false); // Did user chrome backup ok?
var ucBackedUp = new Boolean(false); // Did user content backup ok?
var pwBackedUp = new Boolean(false); // Did passwords backup ok?
var spBackedUp = new Boolean(false); // Did search plugins backup ok?
var hsBackedUp = new Boolean(false); // Did history backup ok?
var ffBackedUp = new Boolean(false); // Did form fill history backup ok?
var pmBackedUp = new Boolean(false); // Did permissions file backup ok?
var udBackedUp = new Number; // Number of User-defined bu's backed up
var upBackedUp = new Boolean(false); // Did the user profile backup ok?
// Backup file names
var bmBuName = new String(); // Bookmarks backup filename
var prBuName = new String(); // Preferences backup filename
var ckBuName = new String(); // Cookies backup filename
var chBuName = new String(); // UserChrome backup filename
var ucBuName = new String(); // UserContent backup filename
var pwBuName = new String(); // Password backup filename
var spBuName = new String(); // Search plugins backup filename
var hsBuName = new String(); // Browser history backup filename
var ffBuName = new String(); // Form fill history backup filename
var pmBuName = new String(); // Permissions backup filename
var udBuName = new String(); // User-defined backup filename
var upBuName = new String(); // User profile backup filename
function febeSetMsgs(){
// Error messages, prompts, etc.
var fs = document.getElementById('febe-strings');
if(!fs) { // Can't find it? Try looking for the FEBE options window
var wm = Cc["@mozilla.org/appshell/window-mediator;1"] .getService(Ci.nsIWindowMediator);
var enumerator = wm.getEnumerator("febe:options");
while(enumerator.hasMoreElements()) {
var win = enumerator.getNext();
fs = win.document.getElementById('febe-strings');
}//while
}//if
var enumerator = fs.strings;
var cnt=0;
var id="";
while (enumerator.hasMoreElements()) {
if(cnt > 9){
id = cnt.toString();
}else{
id = "0" + cnt.toString();
}// if
var msg = "msg"+id;
try{
febeMsg.push(fs.getString(msg));
}catch(e){;}
enumerator.getNext();
cnt++;
}//while
return true;
}//febeSetMsgs()
function febeGetPrefs(){
// Get/set the preferences
febeUseTimestampedDir = febePrefs.getBoolPref("extensions.febe.useTimestampedDir");
febeMaxDirs = febePrefs.getIntPref("extensions.febe.maxBuDirs");
febeClearDestDir = febePrefs.getBoolPref("extensions.febe.clearDestDir");
febeBUtype = febePrefs.getCharPref("extensions.febe.buType");
if(febeBUtype == "selective"){
buProfile = false;
}else{
buProfile = true;
}//if
buExtensions = febePrefs.getBoolPref("extensions.febe.buExtensions");
buThemes = febePrefs.getBoolPref("extensions.febe.buThemes");
buBookmarks = febePrefs.getBoolPref("extensions.febe.buBookmarks");
buPreferences = febePrefs.getBoolPref("extensions.febe.buPreferences");
buCookies = febePrefs.getBoolPref("extensions.febe.buCookies");
buUserChrome = febePrefs.getBoolPref("extensions.febe.buUserChrome");
buUserPwd = febePrefs.getBoolPref("extensions.febe.buUserPwd");
buSearchPlugins = febePrefs.getBoolPref("extensions.febe.buSearchPlugins");
buBrowserHistory = febePrefs.getBoolPref("extensions.febe.buBrowserHistory");
buFormFillHistory = febePrefs.getBoolPref("extensions.febe.buFormFillHistory");
buPermissions = febePrefs.getBoolPref("extensions.febe.buPermissions");
buUDBu = febePrefs.getBoolPref("extensions.febe.buUDBu");
ignoreDisabled = febePrefs.getBoolPref("extensions.febe.ignoreDisabled");
febeVerifyBackups = febePrefs.getBoolPref("extensions.febe.verifyBackups");
febePlaySounds = febePrefs.getBoolPref("extensions.febe.playSounds");
febeHideIcons = febePrefs.getBoolPref("extensions.febe.hideIcons");
febeHideHelp = febePrefs.getBoolPref("extensions.febe.hidehelp");
febeHideHelpIcons();
febeDispProgress = febePrefs.getBoolPref("extensions.febe.displayprogresswin");
febeDispResults = febePrefs.getBoolPref("extensions.febe.displayresultspage");
febeSaveResults = febePrefs.getBoolPref("extensions.febe.saveresultspage");
includeFEBE = febePrefs.getBoolPref("extensions.febe.includefebe");
// Create pointer to profile directory
febeProfDir = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
return true;
}//febeGetPrefs()
function febeBuInProgress(){
return febePrefs.getBoolPref("extensions.febe.backupInProgress");
}//febeBuInProgress()
function febeBuInProgressCheck(){
var style = "<style>color: red; font-weight: bold; font-size: 20px;</style>";
var tmp = style+febeMsg[229]+"\n\n"
style = "<style>color: black; font-size: 14px;</style>";
tmp += style+febeMsg[230]+"\n\n";
style = "<style>color: purple; font-size: 15px;</style>";
tmp += style+febeMsg[231];
if(!febeConfirm(tmp)){
febePrefs.setBoolPref("extensions.febe.backupInProgress",false);
return false;
}//if
return true;
}//febeBuInProgressCheck()
function febeInitPref(prefName, dflt){
// Set a preference to default if needed
if(!febePrefs.prefHasUserValue(prefName)){
febeSetUnicharPref(prefName,dflt);
}else if(febeGetUnicharPref(prefName) == ""){
febeSetUnicharPref(prefName,dflt);
}//if
return true;
}//febeInitPref()
// Object declarations
function febeExtObj(Name, Type, Version, Path, Icon, Home, Guid, Verified, Include, isDisabled, Minversion, Maxversion){
this.Name = new String(Name);
this.Type = new Number(Type);
this.Version = new String(Version);
this.Path = new String(Path);
this.Icon = new String(Icon);
this.Home = new String(Home);
this.Guid = new String(Guid);
this.Verified = new Boolean(Verified);
this.Include = new Boolean(Include);
this.isDisabled = new Boolean(isDisabled);
this.Minversion = new String(Minversion);
this.Maxversion = new String(Maxversion);
return true;
}//febeExtObj
function febeProfileObj(Name, Path){
this.Name = Name;
this.Path = Path;
return true;
}//febeProfileObj object
function febeUDBuDoneObj(Description, Name){
this.Description = Description;
this.Name = Name;
return true;
}//febeUDBuDoneObj()
function febeSetTimeoutObj(PID,Process,Started,Wait){
this.PID = PID;
this.Process = Process;
this.Started = Started;
this.Wait = Wait;
return true;
}//febeSetTimeoutObj
function febeCookieObj(expires, host, isDomain, isSecure, name, path, policy, status, value){
this.expires = expires;
this.host = host;
this.isDomain = isDomain;
this.isSecure = isSecure;
this.name = name;
this.path = path;
this.policy = policy;
this.status = status;
this.value = value;
}//febeCookieObj()
function febePrefObj(Name, Type, Value){
this.Name = Name;
this.Type = Type;
this.Value = Value;
}//febePrefObj()
function febeGetPlatform(){
var platform = navigator.platform.toLowerCase();
if(platform.indexOf("win") != -1){febePlatform = 1;}
if(platform.indexOf("linux") != -1){febePlatform = 2;}
if(platform.indexOf("unix") != -1){febePlatform = 2;}
if(platform.indexOf("darwin") != -1){febePlatform = 3;}
if(platform.indexOf("macintel") != -1){febePlatform = 3;}
if(platform.indexOf("macppc") != -1){febePlatform = 3;}
return febePlatform;
}//febeGetPlatform()
function getFebeVersion() {
var em = Cc["@mozilla.org/extensions/manager;1"].getService(Ci.nsIExtensionManager);
var ext = null;
if (em.getItemForID){
ext = em.getItemForID(FEBE_GUID);
}else{
ext = em.getItemList(FEBE_GUID, null, {})[0];
}//if
return ext.version;
}//getFebeVersion()
function setFebeVersion(){
febeSetMsgs();
if(document.getElementById("febeVersionID")){
var version = getFebeVersion();
document.getElementById("febeVersionID").value = febeMsg[49]+" "+version;
}//if
version = Cc['@mozilla.org/xre/app-info;1'].getService(Ci.nsIXULAppInfo).version;
if(document.getElementById("febeFxVersionID")){
document.getElementById("febeFxVersionID").value = version;
}//if
return true;
}//setFebeVersion()
function febeValidateMaxDirs(){
var maxDirs = document.getElementById("maxBuDirsID").value;
if(isNaN(maxDirs)){
var w = this.window;
febeAlert(febeMsg[101]);
w.focus();
document.getElementById("maxBuDirsID").focus();
document.getElementById("maxBuDirsID").select();
return false;
}//if
document.getElementById("maxBuDirsID").value = parseInt(maxDirs);
return true;
}//febeValidateMaxDirs()
function febeOpenLink(URL){
if(!URL){return;}
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
var febeGetBrowser = win.getBrowser();
var currBlank = (febeGetBrowser &&
(febeGetBrowser.mCurrentTab.linkedBrowser &&
(febeGetBrowser.mCurrentTab.linkedBrowser.contentDocument.location == "about:blank")) ||
(!febeGetBrowser.mCurrentTab.linkedBrowser &&
(febeGetBrowser.mCurrentTab.label == "(Untitled)")));
if (currBlank)
{
var resultsWindow = win.loadURI(URL);
} else {
var resultsWindow = win.openNewTabWith(URL, this.docURL, null, null);
}//if
return true;
}//febeOpenLink()
function febeHideHelpIcons(){
var prefName = "extensions.febe.hidehelp";
febeHideHelp = febePrefs.getBoolPref(prefName);
var c = "helpButton";
if(febeHideHelp){c = "none";}
for(var i=1; i<32; i++){
var seq = String(i);
if(i<10){seq = "0".concat(seq);}
var id = "febeHelp".concat(seq);
try{
document.getElementById(id).setAttribute("class",c) ;
}catch(e){;}
}
return true;
}//febeHideHelpIcons()
function febeOptions(aPaneID){
febeWin = window.openDialog('chrome://febe/content/settings/febeOptions.xul', 'FEBE Options', 'chrome,titlebar,toolbar,centerscreen,resizable');
febeWin.focus();
return true;
}//febeOptions()
function febeHelp(helpIndex,fieldName){
febeWin = window.openDialog("chrome://febe/content/febeHelp.xul", "FEBE Help", "chrome,dialog=yes,alwaysRaised,resizable,titlebar=no,popup=yes",helpIndex,fieldName);
febeWin.focus();
return true;
}//febeHelp()
function febeAlert(message){
// Modal windows don't seem to work on Mac (or *nix, possibly), so let's just take it out for everybody
febeWin = window.openDialog("chrome://febe/content/febeAlert.xul", "FEBE Alert","chrome,dialog=yes,alwaysRaised,resizable,titlebar=no,popup=yes" ,message);
febeWin.focus();
return true;
}//febeAlert()
function febeConfirm(message){
febeWin = window.openDialog("chrome://febe/content/febeConfirm.xul", "FEBE Confirm", "chrome,modal,dialog=yes,alwaysRaised,resizable,titlebar=no,popup=yes",message);
febeWin.focus();
var prefName = "extensions.febe.confirm";
var OK = febePrefs.getBoolPref(prefName);
return OK;
}//febeConfirm()
function febeError(message){
febeWin = window.openDialog("chrome://febe/content/febeError.xul", "FEBE Error", "chrome,dialog=yes,alwaysRaised,resizable,titlebar=no,popup=yes",message);
febeWin.focus();
return true;
}//febeAlert()
function febeConfirmOK(){
var prefName = "extensions.febe.confirm";
febePrefs.setBoolPref(prefName,true);
return true;
}//febeConfirmOK()
function febeConfirmCancel(){
var prefName = "extensions.febe.confirm";
febePrefs.setBoolPref(prefName,false);
return true;
}//febeConfirmOK()
function febeSetAlertMsg(){
febeSetConfirmMsg();
return true;
}//febeSetAlertMsg()
function febeSetConfirmMsg(){
// If the message contains a style, it must be the first part of the message (one style per line, if needed)
var tmp = window.arguments[0]+" \n\n";
var msg = {};
var i = 0;
while(true){ // Break it into an array
var item = new febeAlertObj();
var p = tmp.indexOf("\n");
if(p == -1){break;}
item.Style = "font-family: arial; font-size: 12pt; font-weight: normal; color: purple"; // Default style
var ps1 = tmp.indexOf("<style>");
if(ps1 == 0){
var ps2 = tmp.indexOf("</style>");
if(ps2 != -1){
item.Style = tmp.substr(7,ps2-7); // "7" equals the length of "<style>"
tmp = tmp.replace(tmp.substr(0,ps2+8),""); // Remove the style
p = tmp.indexOf("\n");
}//if
}//if
item.Text = tmp.substr(0,p);
msg[i] = item;
i++;
tmp = tmp.substr(p+1);
}//while
febeClipboard = [];
var msgBox = document.getElementById("febeMsgBox");
if(msgBox){
for(var i in msg){
var desc = document.createElement("description");
desc.textContent = msg[i].Text;
desc.setAttribute("style",msg[i].Style);
msgBox.appendChild(desc);
febeClipboard.push(msg[i].Text);
}//for
document.documentElement.getButton("extra1").hidden = false;
}//if
febePlaySound("alert");
return true;
}//febeSetConfirmMsg()
function febeSliderLoad(){
sizeToContent();
//febeGetPlatform();
febeAlertFinalHeight = window.outerHeight;
window.outerHeight = 1;
var x =(screen.availLeft + screen.availWidth - window.outerWidth) - 10;
var y = screen.availTop + screen.availHeight - window.outerHeight;
//alert(x+"\n"+y)
window.moveTo(x,y);
window.focus();
setTimeout(febeAnimateAlert, 25);
}//febeSliderLoad()
function febeAnimateAlert(){
var febeAlertSliderIncrement = 10; // Amount the slider grows by (pixels)
var febeAlertSliderTime = 25; // Time between increments (milliseconds)
if(window.outerHeight < febeAlertFinalHeight){
window.screenY -= febeAlertSliderIncrement;
window.outerHeight += febeAlertSliderIncrement;
setTimeout(febeAnimateAlert, febeAlertSliderTime);
}//if
}//febeAnimateAlert()
function febeCopyToClipboard(){
// Copy the contents of a febeAlert, febeConfirm, or febeError box to the system clipboard
var gClipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
gClipboardHelper.copyString(febeClipboard.join("\n"));
return true;
}//febeCopyToClipboard()
function febeAlertObj(Text,Style){
this.Text = Text;
this.Style = Style;
return true;
}//febeAlertObj()
function febePlaySound(which){
febePlaySounds = febePrefs.getBoolPref("extensions.febe.playSounds");
if(febePlaySounds == false){return;}
var gSound = Cc["@mozilla.org/sound;1"].createInstance(Ci.nsISound);
var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var soundURL = "chrome://febe/content/sounds/"+which+".wav";
var url = ioService.newURI(soundURL, null, null);
gSound.init();
gSound.play(url);
return true;
}//febePlaySound()
function febePlaySoundHelp(which){
// Alway play sounds in the "Play sounds" help window
var gSound = Cc["@mozilla.org/sound;1"].createInstance(Ci.nsISound);
var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var soundURL = "chrome://febe/content/sounds/"+which+".wav";
var url = ioService.newURI(soundURL, null, null);
gSound.init();
gSound.play(url);
return true;
}//febePlaySoundHelp()
function febeParent(pathname){
// Return the parent of pathname. Ex:
// If pathname is "C:\Documents and Settings\Owner\My Documents\some dir",
// the function will return "C:\Documents and Settings\Owner\My Documents"
var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(pathname);
return file.parent.path;
}//febeParent()
function febeLeafname(pathname){
// Return the leafname of pathname. Ex:
// If pathname is "C:\Documents and Settings\Owner\My Documents\some dir",
// the function will return "some dir"
var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(pathname);
return file.leafName;
}//febeLeafname()
function febePause(millis){
// Pause for (millis) milliseconds
var date = new Date();
var curDate = null;
do {curDate = new Date();}
while(curDate-date < millis);
return true;
}//febePause()
function febeWrap(str,len){
// Return a string wrapped at len characters max per line
var tmpA = str.split(" ");
var returnVal="";
var tmp = "";
var skip = new Boolean(false);
for(var i = 0; i < tmpA.length; i++){
tmp += tmpA[i]+" ";
if(tmp.length >= len){
returnVal +="\n"+tmpA[i]+" ";
tmp = "";
i--;
skip = true;
}else{
if(skip == false){returnVal += tmpA[i]+" ";}
skip = false;
}//if
}//for
return returnVal;
}//function febeWrap()
function febeFatal(err,msg){
// Display fatal errors
if(err.toString().indexOf(febeIgnoreError) != -1){return true;}
var style = "<style>color: black;font-size: 8pt;</style>";
var tmp = febeWrap(err.toString(),100);
tmp = tmp.replace(/\n/g,"\n"+style);
tmp = style + tmp;
tmp +="\n\n";
var ptSize = 12;
if(msg.length > 100){ptSize = 8;}
style = "<style>color: red;font-size: "+ptSize+"pt;</style>";
msg = msg.replace(/\n/g,"\n"+style);
tmp += style+msg;
febeError(tmp);
return true;
}//febeFatal()
function febeLocalizedDate(aDate){
var lDate = new Date(aDate)
return lDate.toLocaleDateString()+" "+lDate.toLocaleTimeString();
}//febeLocalizedDate()
function febeNewDirName(which,dirName){
// Rename timestamped directories from/to ISO8601 to European
var str = dirName.substr(10,5);
switch(which){
case 0: // Rename DD.MM to MM-DD
str = str.substr(3,2)+"-"+str.substr(0,2);
break;
case 1: // Rename MM-DD to DD.MM
str = str.substr(3,2)+"."+str.substr(0,2);
break;
}//switch
var newName = dirName.substr(0,10) + str + dirName.substr(15);
return newName;
}//febeNewDirName(which,dirName)
function febeExtInfo(extGuid){
// Get extension info from extensions.rdf
var rdfs = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
var profileDir = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
profileDir.append("extensions.rdf");
// Fix for international characters
var ioServ = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var fph = ioServ.getProtocolHandler("file").QueryInterface(Ci.nsIFileProtocolHandler);
var srcFile = fph.getURLSpecFromFile(profileDir);
var ds = rdfs.GetDataSourceBlocking(srcFile);
// Use old method if something comes up undefined
var em = Cc["@mozilla.org/extensions/manager;1"].getService(Ci.nsIExtensionManager);
var ext = null;
if (em.getItemForID){
ext = em.getItemForID(extGuid);
}else{
ext = em.getItemList(extGuid, null, {})[0];
}//if
if(!ext){
var style = "<style>color: red;font-size: 12pt;</style>";
var tmp = style+febeMsg[219].replace("%GUID%",extGuid)+"\n"
febeAlert(tmp);
return false;
}//if
var subject = rdfs.GetResource("urn:mozilla:item:"+extGuid);
var prefix = "http://www.mozilla.org/2004/em-rdf#";
// Guid
this.guid = extGuid;
// Name
var predicate = rdfs.GetResource(prefix + "name");
var name = ds.GetTarget(subject, predicate, true);
if(name){
this.name = name.QueryInterface(Ci.nsIRDFLiteral).Value;
}else{
this.name = ext.name;
}//if
if(!this.name){this.name="(none)";}
// Version
var predicate = rdfs.GetResource(prefix + "version");
var version = ds.GetTarget(subject, predicate, true);
if(version){
this.version = version.QueryInterface(Ci.nsIRDFLiteral).Value;
}else{
this.version = ext.version;
}//if
if(!this.version){this.version="(none)";}
// Description
var predicate = rdfs.GetResource(prefix + "description");
var description = ds.GetTarget(subject, predicate, true);
if(description){this.description = description.QueryInterface(Ci.nsIRDFLiteral).Value;}
if(!this.description){this.description="(none)";}
// Home Page URL
var predicate = rdfs.GetResource(prefix + "homepageURL");
var homepageURL = ds.GetTarget(subject, predicate, true);
if(homepageURL){this.homepageURL = homepageURL.QueryInterface(Ci.nsIRDFLiteral).Value;}
if(!this.homepageURL){this.homepageURL="";}
// Creator
var predicate = rdfs.GetResource(prefix + "creator");
var creator = ds.GetTarget(subject, predicate, true);
if(creator){this.creator = creator.QueryInterface(Ci.nsIRDFLiteral).Value;}
if(!this.creator){this.creator="(none)";}
// Disabled?
var predicate = rdfs.GetResource(prefix + "userDisabled");
var userDisabled = ds.GetTarget(subject, predicate, true);
if(userDisabled){
this.isDisabled = userDisabled.QueryInterface(Ci.nsIRDFLiteral).Value;
}else{
this.isDisabled = false;
}//if
// iconURL
var predicate = rdfs.GetResource(prefix + "iconURL");
var iconURL = ds.GetTarget(subject, predicate, true);
if(iconURL){
this.iconURL = iconURL.QueryInterface(Ci.nsIRDFLiteral).Value;
}else{
this.iconURL = ext.iconURL;
}//if
if(!this.iconURL){this.iconURL="chrome://mozapps/skin/xpinstall/xpinstallItemGeneric.png";}
// minVersion
this.minVersion = ext.minAppVersion;
if(!this.minVersion){this.minVersion="(none)";}
// maxVersion
this.maxVersion = ext.maxAppVersion;
if(!this.maxVersion){this.maxVersion="(none)";}
// installLocation
var predicate = rdfs.GetResource(prefix + "installLocation");
var installLocation = ds.GetTarget(subject, predicate, true);
if(installLocation){this.installLocation = installLocation.QueryInterface(Ci.nsIRDFLiteral).Value;}
if(!this.installLocation){this.installLocation="(none)";}
// parseType
var predicate = rdfs.GetResource(prefix + "type");
var parseType = ds.GetTarget(subject, predicate, true);
if(parseType){
this.type = parseType.QueryInterface(Ci.nsIRDFInt).Value;
}else{
this.type = ext.type;
}//if
// internalName
var predicate = rdfs.GetResource(prefix + "internalName");
var internalName = ds.GetTarget(subject, predicate, true);
if(internalName){this.internalName = internalName.QueryInterface(Ci.nsIRDFLiteral).Value;}
if(!this.internalName){this.internalName="(none)";}
// updateURL
var predicate = rdfs.GetResource(prefix + "updateURL");
var updateURL = ds.GetTarget(subject, predicate, true);
if(updateURL){this.updateURL = updateURL.QueryInterface(Ci.nsIRDFLiteral).Value;}
if(!this.updateURL){this.updateURL="(none)";}
// optionsURL
var predicate = rdfs.GetResource(prefix + "optionsURL");
var optionsURL = ds.GetTarget(subject, predicate, true);
if(optionsURL){this.optionsURL = optionsURL.QueryInterface(Ci.nsIRDFLiteral).Value;}
if(!this.optionsURL){this.optionsURL="(none)";}
// aboutURL
var predicate = rdfs.GetResource(prefix + "aboutURL");
var aboutURL = ds.GetTarget(subject, predicate, true);
if(aboutURL){this.aboutURL = aboutURL.QueryInterface(Ci.nsIRDFLiteral).Value;}
if(!this.aboutURL){this.aboutURL="(none)";}
// availableUpdateURL
var predicate = rdfs.GetResource(prefix + "availableUpdateURL");
var availableUpdateURL = ds.GetTarget(subject, predicate, true);
if(availableUpdateURL){this.availableUpdateURL = availableUpdateURL.QueryInterface(Ci.nsIRDFLiteral).Value;}
if(!this.availableUpdateURL){this.availableUpdateURL="(none)";}
// availableUpdateHash
var predicate = rdfs.GetResource(prefix + "availableUpdateHash");
var availableUpdateHash = ds.GetTarget(subject, predicate, true);
if(availableUpdateHash){this.availableUpdateHash = availableUpdateHash.QueryInterface(Ci.nsIRDFLiteral).Value;}
if(!this.availableUpdateHash){this.availableUpdateHash="(none)";}
// availableUpdateVersion
var predicate = rdfs.GetResource(prefix + "availableUpdateVersion");
var availableUpdateVersion = ds.GetTarget(subject, predicate, true);
if(availableUpdateVersion){this.availableUpdateVersion = availableUpdateVersion.QueryInterface(Ci.nsIRDFLiteral).Value;}
if(!this.availableUpdateVersion){this.availableUpdateVersion="(none)";}
// contributors
var predicate = rdfs.GetResource(prefix + "contributor");
var targets = ds.GetTargets(subject, predicate, true);
var contributors = [];
if(targets){
while (targets.hasMoreElements()){
var contributor = targets.getNext();
if (contributor instanceof Ci.nsIRDFLiteral){
contributors.push(contributor.Value);
}//if
}//while
this.contributors = contributors;
}//if
return true;
}//febeExtInfo()
function febeStripSpaces(extName){
// Remove spaces and undesirable characters from extension name
var tmp = "";
var mask = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
mask += ".+-_";
for (var i = 0; i <= extName.length; i++){
var c = extName.charAt(i);
if( mask.indexOf(c) != -1 ){tmp += c};
}//for
return tmp;
}//febeStripSpaces()
function febeCopyFile(sourcefile,destdir,dName){
if(dName == "parent.lock"){return true;} // File is locked
// get a component for the file to copy
var aFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
if (!aFile) return false;
// get a component for the directory to copy to
var aDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
if (!aDir) return false;
// next, assign URLs to the file components
aFile.initWithPath(sourcefile);
aDir.initWithPath(destdir);
// delete the destination file if it exists
var oFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
oFile.initWithPath(destdir);
oFile.append(dName);
try{
oFile.remove(false);
}catch(e){
//alert(e);
}
// finally, copy the file, renaming it
try{
aFile.copyTo(aDir,dName);
}catch(e){
var msg = febeMsg[168].replace("%sourcefile%",sourcefile+"\n");
msg = msg.replace("%destdir%",destdir+"\n");
msg = msg.replace("%dName%",dName);
febeFatal(e,msg);
return false;
}
return true;
}//febeCopyFile
function febeObfuscate(bool, str){
//Modified base64 obfuscation
switch(bool){
case true:
try{ //Bug 439711 - btoa does not work on unicode characters, so use encodeURIComponent() instead
var test = btoa(str);
}catch(e){
str = "0"+encodeURIComponent(str);
return str.toString();
}//try
var r=Math.floor(Math.random()*4+2);
for(var i=0; i<r; i++){
str = btoa(str);
}
return i.toString()+str;
break;
case false:
var c = new Number(str.charAt(0));
str = str.substr(1);
if(c == 0) {return decodeURIComponent(str);}
for(var i=0; i<c; i++){
str = atob(str);
}
return str;
break;
default:
return null;
break;
}
}//febeObfuscate()
function febeChmod(aDir){
// Recursively set file permissions
// Directories: 0755
// Files: 0644
if(febePlatform == 1) return true; // Don't bother with Windows
var aFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
if (!aFile) return false;
aFile.initWithPath(aDir);
var entries = aFile.directoryEntries;
while(entries.hasMoreElements()){
var entry = entries.getNext();
entry.QueryInterface(Ci.nsIFile);
var src = entry.path;
if(entry.isDirectory()){
entry.permissions = 0755;
febeChmod(src);
}else{
entry.permissions = 0644;
}//if
}//while
return true;
}//febeChmod()
function febeEscape(str){
// Convert apostrophes to double quotes
return str.replace(/\'/g,'"');
}//febeEscape()
function febeProps(e)
{
var obj = e;
if (e === null) {
alert("props called with null argument", "error");
return;
}
if (e === undefined) {
alert("props called with undefined argument", "error");
return;
}
var ns = ["Methods", "Fields", "Unreachables"];
var as = [[], [], []]; // array of (empty) arrays of arrays!
var p, j, i; // loop variables, several used multiple times
var protoLevels = 0;
for (p = e; p; p = p.__proto__)
{
for (i=0; i<ns.length; ++i)
as[i][protoLevels] = [];
++protoLevels;
}
var tmp = "";
var c = 0
for(var a in e){
tmp += a;
try{
tmp += " = "+obj[a] + "\n";
}catch(x){tmp += "\n";}
c++;
if(tmp.length > 500){
alert(tmp);
tmp = "";
c = 0;
}
continue;
// Shortcoming: doesn't check that VALUES are the same in object and prototype.
var protoLevel = -1;
try
{
for (p = e; p && (a in p); p = p.__proto__)
++protoLevel;
}
catch(er) { protoLevel = 0; } // "in" operator throws when param to props() is a string
var type = 1;
try
{
if ((typeof e[a]) == "function")
type = 0;
}
catch (er) { type = 2; }
as[type][protoLevel].push(a);
}
alert(tmp);
function times(s, n) { return n ? s + times(s, n-1) : ""; }
for (j=0; j<protoLevels; ++j)
for (i=0;i<ns.length;++i)
if (as[i][j].length)
alert(
ns[i] + times(" of prototype", j),
(onePerLine ? "\n\n" : "") + as[i][j].sort().join(onePerLine ? "\n" : ", ") + (onePerLine ? "\n\n" : ""),
"propList"
);
}//props()
//alert("febeCommon.js loaded");